<?php 
class ControllerAccountGitLogin extends Controller {
	private $error = array();
	
	public function index() {
		if (($this->request->server ['REQUEST_METHOD'] == 'POST')) {
			$json_response = array ();
			if (isset ( $this->request->post ['email'] ) && isset ( $this->request->post ['password'] ) && $this->validate ()) {
				unset ( $this->session->data ['guest'] );
				$this->load->model ( 'account/address' );
				$address = $this->model_account_address->getAddress ( $this->customer->getAddressId () );
				$json_response ['status'] = 'OK';
			} else {
				$json_response ['status'] = 'passwordError';
			}
			echo json_encode ( $json_response );
			exit ();
		}
	}
	
	private function validate() {
		if (! $this->customer->login ( $this->request->post ['email'], $this->request->post ['password'] )) {
			$this->error ['message'] = $this->language->get ( 'error_login' );
		}
		
		if (! $this->error) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
}
?>
